package graphBuilder;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Stroke;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import org.jgrapht.WeightedGraph;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.SimpleWeightedGraph;
import org.jgrapht.graph.WeightedPseudograph;

import Shared.MapPosition;
import Shared.Utils;
import Simulator.GUI;


public class graphTester extends JPanel
{
	private static final long serialVersionUID = 1L;
	private String londra = "../gui/londra.jpg";
	private Image mybackground;
	private String punaise = "../gui/pin.png";
	private Image mypin;
	//String graph_bin_filename = "../img/thoralf.bin";
	private WeightedGraph<MapPosition, DefaultWeightedEdge> graph = null;
	private WeightedPseudograph<MapPosition, DefaultWeightedEdge> pseudograph = null;

	public graphTester(SimpleWeightedGraph<MapPosition,DefaultWeightedEdge> graph2) 
	{
		//loadGraph();
		this.graph = graph2;

		ImageIcon pin = new ImageIcon(this.getClass().getResource(punaise));
		mypin = pin.getImage();

		ImageIcon back = new ImageIcon(this.getClass().getResource(londra));
		mybackground = back.getImage();

		setFocusable(true);
		setBackground(Color.BLACK);
		setDoubleBuffered(true);
		
		new GUI((JPanel) this);

	}
	
	public graphTester(WeightedPseudograph<MapPosition,DefaultWeightedEdge> graph2) 
	{
		Utils.disp("pseudo !");
		//loadGraph();
		this.graph = graph2;

		ImageIcon pin = new ImageIcon(this.getClass().getResource(punaise));
		mypin = pin.getImage();

		ImageIcon back = new ImageIcon(this.getClass().getResource(londra));
		mybackground = back.getImage();

		setFocusable(true);
		setBackground(Color.BLACK);
		setDoubleBuffered(true);
		
		new GUI((JPanel) this);

	}



	public void paint(Graphics g) 
	{
		super.paint(g);

		Graphics2D g2d = (Graphics2D)g;
		g2d.drawImage(mybackground, 0, 0, null); 


		for(DefaultWeightedEdge  edge: graph.edgeSet())
		{
			Point a = graph.getEdgeSource(edge).getPoint();
			Point b = graph.getEdgeTarget(edge).getPoint();
			
			
			Stroke s = g2d.getStroke();
			g2d.setStroke(new BasicStroke(5));
	
			g2d.drawLine((int) a.getX() , (int) a.getY(), (int) b.getX(), (int) b.getY());
			g2d.drawImage(mypin,((int) a.getX() - 2),((int) a.getY() -2), this); 
			g2d.drawImage(mypin,((int) b.getX() - 2),((int) b.getY() -2), this); 
			
			g2d.setStroke(s);

		}

		Toolkit.getDefaultToolkit().sync();
		g.dispose();
	}
}
	







	